<template>
  <div class="comment" v-if="$route.params">
    <my-header title="发表评论">
      <template #right>
        <van-button
          round
          type="info"
          size="small"
          color="linear-gradient(to right, #ff6034, #ee0a24)"
          @click="publish"
          >发布</van-button
        >
      </template>
    </my-header>

    <div class="wrap">
      <div class="wraptop">
        <van-card
          :title="this.$route.params.name"
          :desc="'「' + this.$route.params.ipRightList[0].ipRightName + '」'"
          :thumb="this.$route.params.img[0]"
        />
        <div class="write">
          <van-field
            v-model="message"
            rows="2"
            autosize
            type="textarea"
            maxlength="80"
            placeholder="快和同好分享你的心得感受，能帮助更多人哦~"
            show-word-limit
          />
        </div>
      </div>

      <div class="wrapbottom">
        <p><span>描述相符</span><van-rate v-model="value" /></p>
        <p><span>物流服务</span><van-rate v-model="value1" /></p>
        <p><span>服务态度</span><van-rate v-model="value2" /></p>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      // rate
      value: 0,
      value1: 0,
      value2: 0,

      // vant输入框的值
      message: "",
    };
  },
  methods: {
    // 输入框事件
    changeVanText(value) {
      console.log(value);
    },
    // 点击发布按钮，发送输入框的值和rate的值
    async publish() {
      console.log(this.message);
      console.log(this.message.length);
      console.log(this.value, this.value1, this.value2);
      // 判断是否满足提交条件 (大于十五字)
      if (this.message.length >= 15) {
        let res = await this.$ajax.addCommentToOLCommentData({
          phone: this.userInfo.phone,
          content: this.message,
          rate: [this.value, this.value1, this.value2],
          gid: this.$route.params.itemsId,
        });
        console.log(res);
        if (res.length > 0) {
          this.ShowSuccess("评论成功");
        }
      } else {
        this.$dialog
          .alert({
            message: "需要大于十五字才能评论哦~",
          })
          .then(() => {
            // on close
          });
      }
    },
  },
  mounted() {
    console.log(this.$route.params);
  },
};
</script>

<style lang="scss" scoped>
.comment {
  width: 100%;
  background: #eee;
  ::v-deep .van-button {
    width: 60px;
  }
  .wrap {
    width: 100%;
    padding: 12px 12px;
    .wraptop {
      background: #fff;
      border-radius: 10px;
      ::v-deep .van-card {
        background: #fff;
        border-radius: 10px;
      }
    }
    .wrapbottom {
      background: #fff;
      margin-top: 12px;
      border-radius: 10px;
      padding: 20px 12px;
      p {
        margin-top: 10px;
      }
      span {
        margin-right: 15px;
      }
    }
  }
}
</style>